<script lang="ts">
  import type { PageData } from "./$types";
  import Giscus from "$lib/components/Giscus.svelte";

  let { data }: { data: PageData } = $props();

  function formatDate(dateStr: string): string {
    return new Date(dateStr).toLocaleDateString("en-US", {
      year: "numeric",
      month: "long",
      day: "numeric",
    });
  }
</script>

<svelte:head>
  <title>{data.metadata.title} | My Blog</title>
  <meta name="description" content={data.metadata.description} />
</svelte:head>

<article>
  <header>
    <h1>{data.metadata.title}</h1>
    <p>
      <time datetime={data.metadata.date}>{formatDate(data.metadata.date)}</time
      >
    </p>
  </header>

  <data.content />
</article>

<Giscus />

<a href="/">← Back to all posts</a>
